package rush.rushcampus.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import rush.rushcampus.common.Result;
import rush.rushcampus.dto.ErrandDto;
import rush.rushcampus.dto.ErrandPageDto;
import rush.rushcampus.service.IErrandService;
import rush.rushcampus.service.impl.ErrandServiceImpl;

/**
 * <p>
 *
 * </p>
 *
 * @author rush
 * @since 2024-09-06
 */
@RestController
@Api(tags = "跑腿")
@RequestMapping("/errand")
public class ErrandController {
    @Autowired
    private ErrandServiceImpl errandService;
    @ApiOperation("新增跑腿")
    @PostMapping("/add")
    public Result add(@RequestBody ErrandDto errandDto){
        errandService.add(errandDto);
        return Result.success("新增成功");
    }
    @ApiOperation("删除跑腿")
    @DeleteMapping ("/remove")
    public Result remove(Long id){
        errandService.removeErrand(id);
        return Result.success("删除成功");
    }
    @ApiOperation("获取该用户下的跑腿信息(用户id：1)（为了增强效率，展示页面和详情页面和该用户接单页面都共用这个api）")
    @PostMapping("/listByUser")
    public Result list(@RequestBody ErrandPageDto errandPageDto){
        return Result.success(errandService.listByUser(errandPageDto));
    }
    @ApiOperation("用户接单(用户id为1)")
    @GetMapping("/accept")
    public Result accept(Long id){
        errandService.accept(id);
        return Result.success("接单成功");
    }
    @ApiOperation("接单完成受理")
    @GetMapping("/finish")
    public Result finish(Long id){
        errandService.finish(id);
        return Result.success("完成受理");
    }
    @ApiOperation("跑腿信息分页查询(考虑到意义不大，故根据id查询接口不做开发)")
    @PostMapping("/list")
    public Result pageList(@RequestBody ErrandPageDto errandPageDto){
        return Result.success(errandService.ErrrandVoList(errandPageDto, null));
    }

}
